<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">
    <h:head>
        <title>Mi carro de la compra</title>
    </h:head>
    <h:body>
        <ui:composition template="template.xhtml">
            <ui:define name="content">
                <h:form id="cartForm">
                    <p:dataTable id="cartTable" styleClass="adminTable" var="product" value="#{cartBean.cartProducts}"
                                 emptyMessage="Tu carrito está vacío.">

                        <f:facet name="header">
                            <h:outputText styleClass="headerTitle" value="Mi carro de la compra" />
                            <p:commandLink action="#{cartBean.confirmOrder()}">
                                <p:graphicImage styleClass="imgBtn imgBtnOk" url="resources/images/ok.png" alt="Confirmar compra" title="Confirmar compra" />
                            </p:commandLink>
                        </f:facet>
                        <p:column headerText="Nombre">
                            <h:outputText value="#{product.item.name}" />
                        </p:column>
                        <p:column headerText="Cantidad">
                            <h:outputText value="#{product.quantity}" />
                        </p:column>
                        <p:column headerText="Precio">
                            <h:outputText value="#{product.purchasePrice}€" >
                                <f:convertNumber currencySymbol="€" type="currency" />
                            </h:outputText>
                        </p:column>
                        <p:column headerText="Total">
                            <h:outputText value="#{product.total}">
                                <f:convertNumber currencySymbol="€" type="currency" />
                            </h:outputText>
                        </p:column>
                        <p:column width="2%">
                            <p:commandLink id="deleteBtn" action="#{cartBean.removeProduct}" update="@form" >
                                <f:setPropertyActionListener value="#{product}" target="#{cartBean.selectedProduct}" />
                                <p:graphicImage styleClass="tableBtn" url="resources/images/delete.png" height="24px" alt="Eliminar del carro" title="Eliminar del carro" />
                            </p:commandLink>
                        </p:column>
                        <f:facet name="footer">
                            <p:summaryRow rendered="#{cartBean.cartProducts.size()>0}">
                                <p:column colspan="3" style="text-align:right">
                                    Total:
                                </p:column>

                                <p:column>
                                    #{cartBean.purchaseTotal}€
                                </p:column>
                            </p:summaryRow>
                        </f:facet>
                    </p:dataTable>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

